//
//  UserManager+IM.swift
//  SitPosition
//
//  Created by apple on 2019/1/6.
//  Copyright © 2019 apple. All rights reserved.
//

import Foundation

extension UserManager {
    
    // 登录环信
    func loginIM(role: UserRole) {
        // 判断当前用户的登录状态
        guard isLogin(), let user = self.user else {
            return
        }
        // 登录环信
        let matchedObject: User.IMAccount? = user.ringAccount?.first { obj in
            return obj.type == role.rawValue
        }
        if let ringAccount = matchedObject {
            EMClient.shared()?.login(withUsername: ringAccount.id, token: ringAccount.password, completion: { (username, error) in
                if error == nil {
                    print("IM：登录成功")
                } else {
                    print("IM：登录失败")
                }
            })
        }
    }
}
